<?php
/**
 * 用户
 * @author gary
 **/
class Services_Auth_Stulogin extends Fend
{

    private $_memcache = '';
    public static function factory()
    {
        return new self();
    }

    public function __construct()
    {
        $config = Fend_Di::factory()->get('memcacheconfig');
        $this->_memcache =new \memcache;;
        $this->_memcache->connect($config['stusess']['host'], $config['stusess']['port']);
    }

    public function checkLogin($cookie='')
    {
        $wx = !empty($cookie)?$cookie:'';
        $wx = !empty($_COOKIE['wx'])?$_COOKIE['wx']:$wx;
        if(empty($wx)){
            return false;
        }
        $string =$this->_memcache->get($wx);
        if(empty($string)){
            return false;
        }

        $uinfo = Fend_Func::load()->unserialize_php($string);

        if (!$uinfo) {
            return false;
        }

        Fend_Di::factory()->set('user_info',$uinfo);
        return $uinfo;
    }
}
